package com.guaoran.algorithm.entity;

/**
 * @Desc： 节点元素
 * @Auth gucheng
 * @Date 2020/12/16 上午10:13
 */
public class NodeList<T> {
    public Node<T> head;

    public NodeList<T> add(T data){
        Node<T> node = new Node<>(data);
        if(head==null){
            head = node;
        }else{
            Node<T> first = head;
            while((first.next) != null){
                first = first.next;
            }
            first.next = node;
        }
        return this;
    }
    public NodeList<T> addNode(Node node){
        if(head==null){
            head = node;
        }else{
            Node<T> first = head;
            while((first.next) != null){
                first = first.next;
            }
            first.next = node;
        }
        return this;
    }
    @Override
    public String toString() {
        return head + "";
    }
}
